package com.booking.springrestful.controller;

import com.booking.springrestful.domain.Users;
import com.booking.springrestful.domain.dto.CounselorsDto;
import com.booking.springrestful.domain.dto.CounselorsSaveDto;
import com.booking.springrestful.domain.request.userBodyRequest;
import com.booking.springrestful.domain.vo.CounselorsUpVo;
import com.booking.springrestful.domain.vo.CounselorsVo;
import com.booking.springrestful.resp.PageResult;
import com.booking.springrestful.resp.ResponseResult;
import com.booking.springrestful.service.CounselorsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/counselor")
@Slf4j
//咨询师信息模块
public class counselorController {

    @Resource
    private CounselorsService counselorsService;


    //查询所有咨询师账号
    @GetMapping("/getUsername")
    private ResponseResult<List<CounselorsVo>> getUsername(){
        List<CounselorsVo> list= counselorsService.getUsername();
        return ResponseResult.success(list);
    }


    //查询所有咨询师
    @PostMapping ("/getCounselor")
    private ResponseResult<PageResult<CounselorsVo>> getCounselor(@RequestBody CounselorsDto counselorsDto){
        PageResult<CounselorsVo> counselorsVo=counselorsService.getCounselor(counselorsDto);
        return ResponseResult.success(counselorsVo);
    }


    //新增咨询师信息
    @PostMapping("/saveCounselor")
    private ResponseResult saveCounselor(@RequestBody CounselorsSaveDto counselorsSaveDto){
        log.info(counselorsSaveDto.toString());
        counselorsService.saveCounselor(counselorsSaveDto);
        return ResponseResult.success("新增成功");
    }


    //删除
    @PostMapping("/delCounselor")
    private ResponseResult delCounselor(@RequestBody List<CounselorsVo> counselorsVos){
        counselorsService.delCounselor(counselorsVos,"启用状态不可删除");
        return ResponseResult.success("删除成功");
    }


    //根据userid查询咨询师信息
    @GetMapping("/getByUserId")
    private ResponseResult<CounselorsUpVo> getByUserId(Integer userId){
        CounselorsUpVo dto= counselorsService.getByUserId(userId);
        return ResponseResult.success(dto);
    }

    //更新
    @PostMapping("/upCounselor")
    private ResponseResult upCounselor(@RequestBody CounselorsSaveDto counselorsSaveDto){
        counselorsService.upCounselor(counselorsSaveDto);
        return ResponseResult.success("修改成功");
    }


}
